#include <vector>
#include <iostream>

using namespace std;

int countBinarySubstrings(string s) {
    int ptr = 0, n = s.size(), last = 0, ans = 0;
    while (ptr < n) {
        char c = s[ptr];
        int count = 0;
        while (ptr < n && s[ptr] == c) {
            ++ptr;
            ++count;
        }
        ans += min(count, last);
        last = count;
    }
    return ans;
}

// 有问题
int mycountBinarySubstrings(string s) {
    int count = 0;
    for(int i = 0; i < s.size(); i++){
        for(int j = 0; j < i; j++){
            int diff = 0, change = 0; char pre = s[j];
            for(int z = j; z < i; z++){
                if(!(s[z]-pre)){ change++; }
                pre = s[z];
                if(s[z] == '0' && change < 2){
                    diff--;
                }else if(s[z] == '1' && change < 2){
                    diff++;
                }
            }
            if(diff == 0 && change < 2) count++;
        }
    }
    return count;
}

int main(){
    string s = "00110011";
    cout << countBinarySubstrings(s) << endl;
    return 0;
}